/** @file f_zstream.cpp
	@brief Zipped stream */

#include "file/f_zstream.h"

using namespace G3;

//==============================================================================
// Constructors & Destructors
//==============================================================================
G3::ZSTREAM::ZSTREAM (STREAM *stream) {
    Assert (stream, "ZSTREAM::ZSTREAM: Stream argument is a NULL pointer..\n");

    log = &G3::MainLog;

    bStream = stream;

    flags = 0;

	compressionLevel = -1;

	outputChunkSize = ZSTREAM_DEF_CHUNK;
}

G3::ZSTREAM::~ZSTREAM () {
}

//==============================================================================
// Sets the size of a chunk (deflation buffer)
//
//		long ChunkSize			According to zlib documentation, this should be
//								either 131072 (128 KB) or 262144 (256 KB)
//==============================================================================
void G3::ZSTREAM::SetChunkSize (long chunkSize) {
	if (chunkSize >= 16)
		outputChunkSize = chunkSize;
}

//==============================================================================
// Returns true if the ZFILESTREAM is opened with the given flags
//
//		byte OpenFlags				Flags the stream should be opened with
//				ZSTREAM_DEFLATE		Checks if the stream is opened for deflating
//				ZSTREAM_INFLATE		Checks if the stream is opened for inflating
//
//	Returns true if the test was successful
//==============================================================================
bool G3::ZSTREAM::IsOpen (byte openFlags) {
	return ((flags & (openFlags | ZSTREAM_OPEN)) != 0);
}

//==============================================================================
// Enables a flag
//==============================================================================
void G3::ZSTREAM::Enable (ushort flag) {
	flags |= flag;
}

//==============================================================================
// Disables a flag
//==============================================================================
void G3::ZSTREAM::Disable (ushort flag) {
	flags &= (~flag);
}
